package com.zsr.controller;

import com.sun.org.glassfish.gmbal.ParameterNames;
import com.zsr.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @Author zsr
 * @Description RestFul风格
 * @Date 2021/4/28 12:51
 */
@Controller
public class HelloController {

    //http://localhost:8080/springmvc_04_controller/add/1/2

    //get方法
    //@GetMapping("/add/{a}/{b}")
    @RequestMapping(value = "/add/{a}/{b}",method = {RequestMethod.GET})
    public String test1(@PathVariable int a ,@PathVariable int b, Model model){
        model.addAttribute("msg","结果1为:"+(a+b));
        return "forward:test";
    }

    //post方法
    @PostMapping("/add/{a}/{b}")
    public String test2(@PathVariable @RequestParam("a") int a , @PathVariable int b, Model model){
        model.addAttribute("msg","结果2为:"+(a+b));
        return "redirect:test";
    }

    @GetMapping("/t3")
    public String test3(@RequestParam("username") String name,Model model){
        model.addAttribute("username",name);
        return "forward:test";
    }

    @RequestMapping("/ma1")
    public String test3(User u, Model model){
        //jsp页面可以${user}直接获取
        System.out.println(u);
        return "test";
    }
}
